﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 智信科技物流系统
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        private void login_Load(object sender, EventArgs e)
        {
            skinEngine1.SkinFile = "DeepCyan.ssk";
        }
        SqlHelper op = new SqlHelper();
        private void btn_login_Click(object sender, EventArgs e)
        {
            if (tb_username.Text == "")
            {
                MessageBox.Show("用户名不能为空！");
                tb_username.Focus();
                return;
            }
            if (tb_pwd.Text == "")
            {
                MessageBox.Show("密码不能为空！");
                tb_pwd.Focus();
                return;
            }
            Userini.UserName = tb_username.Text.Trim();
            string cmd = "select * from bm_User where UserName=N'" + Userini.UserName + "'";
            DataTable result;
            try
            {

                result = op.SqlSelect(cmd);//密码位于字段2
            }
            catch {
                MessageBox.Show("服务器连接中断，请重试，若依然不可以请联系客服.");
                return;
            }
            
            if (result.Rows.Count<1)//判断用户是否存在
            {
                MessageBox.Show("用户不存在");
                tb_username.Focus();
                return;
            }
            if (tb_pwd.Text.Trim().Equals(result.Rows[0][2]))//判断密码是否正确
            {

                //登陆
                firstload.exit = false;
                Userini.UserName = tb_username.Text.Trim();
                Userini.userinfor = result;//将用户信息写入本地
                this.Close();
            }
            else
            {
                MessageBox.Show("密码错误");
                tb_pwd.Focus();
                return;
            }       

        }

        private void btn_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_Register_Click(object sender, EventArgs e)
        {
            Register frm_reg = new Register();
            frm_reg.ShowDialog();
        }      
    }
}
